package cz.possoft.client.piskvorky.gui.components;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import cz.possoft.client.piskvorky.gui.panel.PiskvorkyPanel;
import cz.possoft.client.utils.PanelHolderUtils;
import cz.possoft.serializable.generic.Location;

/**
  * Listener nastava pri oddelani mysi z sachovnice hry piskvorky
  * nebo pri stisku tlacitka nad touto sachovnici
  *
  * @author mara  
  */
public class PiskvorkyMouseListener extends MouseAdapter {

	// nastava pokud mysi vyjedu z prostoru sachovnice	   
    public void mouseExited(MouseEvent me) {
       	if (!(PanelHolderUtils.getCurrentGamePanel() instanceof PiskvorkyPanel)) {
    		return;
    	}    	    	
        if ((PanelHolderUtils.getCurrentGamePanel().getGame().isActive()) && (PanelHolderUtils.getCurrentGamePanel().getGame().jsemNaTahu())) {
            Location location = new Location(-1, -1);
            ((PiskvorkyPanel)PanelHolderUtils.getCurrentGamePanel()).updateForPlaceWhereIsMouse(location);	            
        }          	
    }

    
    public void mousePressed(MouseEvent me) {
       	if (!(PanelHolderUtils.getCurrentGamePanel() instanceof PiskvorkyPanel)) {
    		return;
    	}    	    	
        if ((PanelHolderUtils.getCurrentGamePanel().getGame().isActive()) && (PanelHolderUtils.getCurrentGamePanel().getGame().jsemNaTahu())
        		&& (!((PiskvorkyPane)(PanelHolderUtils.getCurrentGamePanel().getGamePane())).getRingFigurkaLocation().isNull())) {
                    Location location = PiskvorkyMouseMotionListener.getMouseLocation(me);
                    ((PiskvorkyPanel)PanelHolderUtils.getCurrentGamePanel()).play(location);	            
        }   
    }	
    
}
